<extend name="Public:base" />
<block name="css">
    <link href="__CSS__/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="__CSS__/plugins/select2/select2.css" rel="stylesheet"/>
    <link href="__CSS__/plugins/waitMe/waitMe.min.css" rel="stylesheet">
    <link href="__CSS__/plugins/toastr/toastr.min.css" rel="stylesheet"/>
</block>
<block name="js">
    <script src="__JS__/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="__JS__/plugins/waitMe/waitMe.min.js"></script>
    <script src='__JS__/plugins/select2/select2.js'></script>
    <script src="__JS__/plugins/validForm/Validform_v5.3.2_min.js"></script>
    <script src="__JS__/plugins/toastr/toastr.min.js"></script>
    <script type='text/javascript'>
        $(".select-no-search").select2({theme: "classic", minimumResultsForSearch: -1});
        $(".select-search").select2({theme: "classic"});
        var delete_url = "{:U('Tag/delete')}";
        var search_url = "{:U('Tag/search')}";
        $("#search").click(function () {
            var params = $("#search_form").serialize();
            $("#refresh_box").waitMe(config.waitme);
            loadList(params);
        });
        //加载列表
        function loadList(params, url) {
            if (arguments.length < 2) {
                url = search_url;
            }
            $.post(url, params, afterLoad);
        }
        //加载后的回调函数
        function afterLoad(data) {
            if (data.status == 1) {
                $("#refresh_box").html(data.content);
            } else {
                toastr.error(data.info);
            }
        }
        //获取参数
        function getParams() {
            var params = $("#search_form").serializeArray();
            var sort_name = {name: 'sort_field', value: $("[data-current='true']").attr('data-sort-field')};
            var sort_type = {name: 'sort_type', value: $("[data-current='true']").attr('class')};
            var sort_reverse = {name: 'sort_reverse', value: false};
            params.push(sort_name);
            params.push(sort_type);
            params.push(sort_reverse);
            return params;
        }
        //分页点击
        $("#refresh_box").on('click', '.page a', function () {
            var params = getParams();
            var page = {name: 'page', value: $(this).attr('data-num')};
            params.push(page);
            $("#refresh_box").waitMe(config.waitme);
            loadList(params);
        });
        //删除一条标签
        $("#refresh_box").on('click', '.delete', function () {
            var params = getParams();
            var page = {name: 'page', value: $(".page .active").text()};
            params.push(page);
            var tag_id = {name: 'tag_id', value: $(this).attr('data-id')};
            params.push(tag_id);
            $("#refresh_box").waitMe(config.waitme);
            loadList(params, delete_url);
        });
        //点击排序
        $("#refresh_box").on('click', ".sorting,.sorting_asc,.sorting_desc", function () {
            var params = $("#search_form").serializeArray();
            var sort_name = {name: 'sort_field', value: $(this).attr('data-sort-field')};
            var sort_type = {name: 'sort_type', value: $(this).attr('class')};
            params.push(sort_name);
            params.push(sort_type);
            $("#refresh_box").waitMe(config.waitme);
            loadList(params);
        });
        //表格提交
        $("#form").Validform(config.validform);
    </script>
</block>
<block name="content">
    <div class="col-lg-4" style="padding-left: 0px">
        <div class="ibox float-e-margins">
            <div class="ibox-content clearfix">
                <include file='Tag/_add'/>
            </div>
        </div>
    </div>
    <div class="col-lg-8" style="padding-right: 0px">
        <div class="ibox float-e-margins">
            <div class="ibox-content clearfix">
                <div id='refresh_box'>
                    <include file='Tag/_list'/>
                </div>
            </div>
        </div>
    </div>
</block>